-----以下为清除ACTIVITI相关  开始
delete from ACT_GE_BYTEARRAY

delete from act_evt_log

delete from ACT_RE_DEPLOYMENT
delete from ACT_HI_ATTACHMENT
delete from ACT_HI_COMMENT
delete from ACT_HI_DETAIL
delete from ACT_HI_ACTINST
delete from ACT_HI_PROCINST
delete from ACT_HI_TASKINST
delete from ACT_HI_VARINST
delete from ACT_RU_TASK
delete from ACT_RU_VARIABLE
delete from ACT_RU_JOB
delete from ACT_RU_IDENTITYLINK
delete from ACT_RU_EXECUTION
delete from ACT_RE_PROCDEF
delete from ACT_RE_MODEL

delete from sl_crm_auditNode
update sl_crm_bid set sauditState='未提交'
update sl_crm_contract set sauditState='未提交'
update sl_crm_contractpart set sauditState='未提交'
update sl_crm_contractpump set sauditState='未提交'
update sl_crm_contractrepair set sauditState='未提交'
update sl_crm_quoteForeign set sauditState='未提交'
update sl_crm_quote set sauditState='未提交'
update sl_crm_afterSaleTicketAdvice set sauditState='未提交'
update sl_crm_afterSaleTicket set sticketState='未提交' where safterSaleType='三包办理'
-----清除ACTIVITI相关  结束

-----清除售后相关  开始
delete from sl_crm_afterSaleTicketAdvice
delete from sl_crm_afterSaleTicketback
delete from sl_crm_afterSaleTicketTrance
delete from sl_crm_afterSaleOutHouse
delete from sl_crm_afterTicketPay
delete from sl_crm_afterSaleTicket
-----清除售后相关  结束

----清除价格本相关  开始
delete from sl_crm_singlePump
delete from sl_crm_replaceDevicePrice
delete from sl_crm_wholesetprice
----清除产品相关  结束
delete from sl_crm_device
delete from sl_crm_replacementDevice
delete from sl_crm_wholeSetDevice
-----清除公司信息相关  开始
delete from sl_crm_news
delete from sl_crm_direction
delete from sl_crm_weekly
-----清除公司信息相关  结束

-----清除机会相关  开始
delete FROM [CRM].[dbo].[sl_crm_chanceDelivery] where 
	[saleChance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete FROM [CRM].[dbo].[sl_crm_chanceDeliveryTemp] where 
	[saleChance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete FROM [CRM].[dbo].sl_crm_chanceFlowNode where 
	[chance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete FROM [CRM].[dbo].[sl_crm_chanceKeyMan] where 
	[saleChance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete FROM [CRM].[dbo].[sl_crm_chanceManager] where 
	[saleChance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete FROM [CRM].[dbo].[sl_crm_chanceTrance] where 
	[saleChance_id] in (select id from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%')
delete from [sl_crm_chance] where [sCreator] like '%卓展%' or [sCreator] like '%成套处%'
-----清除机会相关  结束

-----清除报价相关  开始
delete from sl_crm_bidRecord
delete from sl_crm_bid where [sQuoteId] in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quote] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from sl_crm_inventoryReduce where [quoteDevice_id] in (
select id from [sl_crm_quoteDevice] where quoteId in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quote] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)
)

delete from sl_crm_quoteReplacement where quoteId in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quote] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from [sl_crm_quoteDevice] where quoteId in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quote] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from sl_crm_quote where id in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quote] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from sl_crm_bid where [sQuoteForeignId] in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quoteForeign] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from sl_crm_inventoryReduce where [quoteDevice_id] in (
select id from [sl_crm_quoteDevice] where quoteForeignId in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quoteForeign] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)
)

delete from sl_crm_quoteReplacement where [quoteForeignId] in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quoteForeign] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from [sl_crm_quoteDevice] where [quoteForeignId] in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quoteForeign] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)

delete from sl_crm_quoteForeign where id in (
SELECT a.[id]
  FROM [CRM].[dbo].[sl_crm_quoteForeign] a 
  left join sl_au_user b
  on a.user_id = b.id
  where b.name like '%卓展%' or b.name like '%成套处%'
)
-----清除报价相关  结束

-----清除合同相关  开始
delete from sl_crm_contractRepair where [sOperator] like '%卓展%' or [sOperator] like '%成套处%'
delete from sl_crm_contractPump where [sOperator] like '%卓展%' or [sOperator] like '%成套处%'
delete from sl_crm_contractPart where [sOperator] like '%卓展%' or [sOperator] like '%成套处%'
delete from sl_crm_contract where [sOperator] like '%卓展%' or [sOperator] like '%成套处%'
-----清除合同相关  结束

-----清除客户来访相关  开始
delete from sl_crm_customerVisitingCost
delete from sl_crm_customerVisitPerson
delete from sl_crm_customerVisiting
-----清除客户来访相关  结束

-----清除客户相关  开始
delete from sl_crm_keyContact
delete from sl_crm_customer
-----清除客户相关  结束

-----清除日志相关  开始
delete from sl_au_log
-----清除日志相关  结束

-----清除签订前要点审批 开始
delete from tbExdeBeforeContractDetailParts
delete from tbExdeBeforeContractCounterSign
delete from tbExdeBeforeContractDetails
delete from tbExdeBeforeContractSpecialClause
delete from tbExdeBeforeContractWGDetail
delete from tbExdeBeforeContractNotices
delete from tbExdeBeforeContract
-----清除签订前要点审批 结束
